package lesson7;
/**
 * Created with IntelliJ IDEA.
 * User: alisa
 * Date: 02.04.14
 * Time: 12:24
 * To change this template use File | Settings | File Templates.
*/

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;

import java.util.concurrent.TimeUnit;


public class WebDriverFactory {
    /* Browsers constants */
    public static final String CHROME = "chrome";
    public static final String FIREFOX = "firefox";
    public static final String INTERNET_EXPLORER = "ie";
    public static final String HTML_UNIT = "htmlunit";

    /* Firefox profiles */
    public static final String DEFAULT_PROFILE = "default";

    public static WebDriver initDriver(String browser) {
        WebDriver testDriver = null;
        if (browser.equals(FIREFOX))
            testDriver = new FirefoxDriver();
        else if (browser.equals(CHROME)) {
            System.setProperty("webdriver.chrome.driver",
                    "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
            testDriver = new ChromeDriver();
        }

//      else if (browser.equals(INTERNET_EXPLORER)){
//          testDriver = new InternetExplorerDriver();
//      } else if (browser.equals(HTML_UNIT)) {
//          testDriver = new HtmlUnitDriver();
        else
            Assert.fail(ReportWriter.errorDriverUnknown(browser));

        //additional configuration
        testDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        return testDriver;
    }
}

